
#include <cstdio>
#include <iostream>
#include <list>
#include <cstring>
#include <cstdlib>

using namespace std;
///git test
class A
{
#if 1
typedef struct{
    int u8CmdType;
    void (A::*PFUNC)(void);

    //PFUNC pFunc;
} ST_UART_PC_T;
#endif
    private:
        list<ST_UART_PC_T> m_lst_cmd;
    public:
        A(int i)
        {
            //p2 = (i==1)?(&A::funa):(&A::funb);
        }
        void (A::*PFUNC)(void);
        void funa(void)
        {
            puts("A");
        }
        void funb(void)
        {
            puts("B");
        }
        void func(void)
        {
            puts("C");
        }

        void hht001(int i)
        {
            PFUNC = (i==1)?(&A::funa):(&A::funb);
            (this->*PFUNC)();

            ST_UART_PC_T m_uart;
            m_uart.u8CmdType=8;
            m_uart.PFUNC=&A::funa;
            m_lst_cmd.push_back(m_uart);
            m_uart.u8CmdType=8;
            m_uart.PFUNC=&A::funb;
            m_lst_cmd.push_back(m_uart);
            m_uart.u8CmdType=0x0FF;
            m_uart.PFUNC=NULL;
            m_lst_cmd.push_back(m_uart);
            m_uart.u8CmdType=8;
            m_uart.PFUNC=&A::func;
            m_lst_cmd.push_back(m_uart);
            puts("============01");
            list<ST_UART_PC_T>::iterator itmUartCmd;
            for(itmUartCmd=m_lst_cmd.begin(); itmUartCmd != m_lst_cmd.end(); ++itmUartCmd)
            {
                cout << itmUartCmd->u8CmdType << endl <<" ";
                if(itmUartCmd->PFUNC!=NULL)
                {
                    (this->*itmUartCmd->PFUNC)();
                }
            }
            puts("============02");
        }
};

char bufarray[5][200];

const int frame_count_max=10;

typedef struct{
	int ncount;
	int nID[frame_count_max];

    int u8CmdType;
    void (A::*PFUNC)(void);

    //PFUNC pFunc;
} ST_FRAME_T;

ST_FRAME_T frame;

int create_touch_pos(int nline_no,FILE* m_fp_parse)
{
	printf( "bufarray[2]=%s\n",bufarray[2] );

	if(0==strcmp("ABS_MT_TRACKING_ID",bufarray[2]))
	{
		char *endptr;
		frame.nID[frame.ncount]=strtol(bufarray[3],&endptr,16);
		printf( "%s;%02X\n",bufarray[2],frame.nID[frame.ncount]);

	}
	else if(0==strcmp("ABS_MT_POSITION_X",bufarray[2]))
	{

	}
	else if(0==strcmp("ABS_MT_POSITION_Y",bufarray[2]))
	{

	}
	else if(0==strcmp("SYN_MT_REPORT",bufarray[2]))
	{
		frame.ncount++;
	}
	else if(0==strcmp("SYN_REPORT",bufarray[2]))
	{
		char buftmp[256];
		sprintf(buftmp,"%2d;",frame.ncount);

		for(int i=0;i<frame.ncount;i++)
		{
			sprintf(&buftmp[strlen(buftmp)],"%02X",frame.nID[i]);
			if(i<frame.ncount-1)
			{
				sprintf(&buftmp[strlen(buftmp)],"%s",",");
			}
		}
		sprintf(&buftmp[strlen(buftmp)],"%s","\n");
		fwrite(buftmp,strlen(buftmp), 1,m_fp_parse);
		printf( "%s\n",buftmp);

		memset(&frame,0x00,sizeof(ST_FRAME_T));
		for(int i=0;i<frame_count_max;i++)
		{
			frame.nID[i]=0xAA;
		}


	}
	else
	{
		//printf( "bufarray[2]=%s\n",bufarray[2]);
	}

}

int parse_line_data(char* data_line)
{
	char* token = strtok( data_line, " ");
	int nnn=0;
	while( token != NULL )
	{
		/* While there are tokens in "string" */
		//printf( "token=%s\n", token );
		strcpy(bufarray[nnn],token);
		//printf( "bufarray[%d]=%s\n",nnn, bufarray[nnn] );
		/* Get next token: */
		token = strtok( NULL, " ");
		nnn++;
		//printf( "nnn=%d \n", nnn );
	}


	return 0;


}

int main()
{
    char bufrecv[256];
    sprintf(bufrecv,"socket_tvos,register,socket_touch_pos      ok      fdsfasdf    sdfs\n");

	FILE* m_fp_parse=fopen("./getevent-002.txt","a+");
	if(m_fp_parse==NULL)
	{
		printf( "m_fp_parse==NULL\n");
		return 0;
	}

	FILE* m_fp_stm32=fopen("./getevent-001.txt","r");
	if(m_fp_stm32==NULL)
	{
		printf( "m_fp_stm32==NULL\n");
		return 0;
	}

    fseek(m_fp_stm32, 0L, SEEK_SET);
	int nline_no=0;
	memset(&frame,0x00,sizeof(ST_FRAME_T));
	
	for(int i=0;i<frame_count_max;i++)
	{
		frame.nID[i]=0xAA;
	}


    while(fgets(bufrecv,sizeof(bufrecv)-1,m_fp_stm32))
	{
		nline_no++;
		if(0!=strncmp(bufrecv,"/dev/",strlen("/dev/")))
		{
			continue;
		}
		parse_line_data(bufrecv);
		create_touch_pos(nline_no,m_fp_parse);
	}

	fclose(m_fp_stm32);
	fclose(m_fp_parse);
	return 0;

	
#if 0
	char bufarray[5][200];
	{

		char* token = strtok( bufrecv, " ");
		int nnn=0;
		while( token != NULL )
		{
			/* While there are tokens in "string" */
			printf( "token=%s\n", token );
			strcpy(bufarray[nnn],token);
			/* Get next token: */
			token = strtok( NULL, " ");
			nnn++;
			printf( "nnn=%d \n", nnn );
		}

		printf( "###############3333\n");
		for(nnn=0;nnn<3;nnn++)
		{
			printf("%s\n",bufarray[nnn]);
		}
	}
#endif


#if 0

                    char buf1[20];
                    char buf2[20];
                    char buf3[20];

                    char buf[5][20];

                    //int nscanf=sscanf(bufrecv,"%s,%s,%s",buf1,buf2,buf3);
                    //int nscanf=sscanf(bufrecv,"%12s%9s%s",buf1,buf2,buf3);
                    int nscanf;//=sscanf(bufrecv,"%[^,]%[^,]%s",buf1,buf2,buf3);

    char* token = strtok( bufrecv, ",");
    int i=0;
    while( token != NULL )
    {
        /* While there are tokens in "string" */
        printf( "%s \n", token );
        strcpy(buf[i],token);
        /* Get next token: */
        token = strtok( NULL, ",");
        i++;
        printf( "i=%d \n", i );

    }
    for(i=0;i<3;i++)
    {
                    printf("%s\n",buf[i]);

    }


                    printf("%s;%s;%d;;;\n",__FILE__,__func__,__LINE__);
                    printf("%d;%s;%s;%s;;;\n",nscanf,buf1,buf2,buf3);

                    if(0==strncmp(buf2,"register",strlen("register")))
                    {
                     printf("%s;%s;%d;;;\n",__FILE__,__func__,__LINE__);
   
                    }

printf("%s;%s;%d;;;\n",__FILE__,__func__,__LINE__);

#endif


    A a(2);
    a.hht001(2);

    //GFUNC = a.PFUNC;
    //(a.*GFUNC)();
    return 0;
}

